package org.example.hotel.service;

import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class LoginService {

    // 简单内存存储，真实系统中应使用数据库
    private final Map<String, String> roomPasswords = new ConcurrentHashMap<>();
    private final Map<String, String> systemPasswords = Map.of(
            "frontdesk", "123456",
            "airadmin", "123456",
            "manager", "123456"
    );

    public LoginService() {
        // 初始化20个房间，密码都设为"00000000"
        for (int i = 101; i <= 110; i++) {
            roomPasswords.put(String.valueOf(i), "00000000");
        }
        for (int i = 201; i <= 210; i++) {
            roomPasswords.put(String.valueOf(i), "00000000");
        }
    }

    public boolean validateRoomLogin(String roomNumber, String password) {
        return roomPasswords.containsKey(roomNumber) && roomPasswords.get(roomNumber).equals(password);
    }

    public boolean validateSystemLogin(String role, String password) {
        return systemPasswords.containsKey(role) && systemPasswords.get(role).equals(password);
    }
}
